package com.example.ruiji.controller.article;

import com.example.ruiji.dao.mapper.ArticleMapper;
import com.example.ruiji.pojo.Category;
import com.example.ruiji.pojo.Ltag;
import com.example.ruiji.service.article.ArticleServiceImpl;
import com.example.ruiji.service.category.CategoryServiceImpl;
import com.example.ruiji.service.ltag.LtagServiceImpl;
import com.example.ruiji.utils.dos.ArchivedDo;
import com.example.ruiji.utils.vo.Result;
import com.example.ruiji.utils.vo.param.ArticleVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Conditional;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * Author:BaiYiChen
 * Date:2022/4/28 13:41
 *
 * @author BaiYiChen
 */
@Controller
@RequestMapping("/articles")
public class ShowDetail {
  @Autowired
  private ArticleServiceImpl articleService;
  @Autowired
  private ArticleMapper articleMapper;
  @Autowired
  private CategoryServiceImpl categoryService;
  @Autowired
  private LtagServiceImpl ltagService;
  
  @GetMapping("/showDetail/{id}")
  public String showDetail(@PathVariable("id")Integer articleId, Model model){
    ArticleVo articleById = articleService.findArticleById(articleId);
    model.addAttribute("article",articleById);
    return "showDetail";
  }
  
  @GetMapping("/category")
  public String category(Model model){
    List<Category> categories = categoryService.findAllCategory();
    List<Ltag> ltags = ltagService.findAllLtag();
    
    model.addAttribute("categories",categories);
    model.addAttribute("ltags",ltags);
    return "category";
  }
  @GetMapping("/showCategory/{aId}")
  public String showCategory(@PathVariable("aId")Integer id,Model model){
    Category category = categoryService.findCategoryById(id);
    model.addAttribute("category",category);
    return "showCategory";
  }
  @GetMapping("/showArchived")
  public String showArchived(Model model){
    List<ArchivedDo> arch = articleMapper.articleArch();
    model.addAttribute("arch", arch);
    return "showArchived";
  }
}
